import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class KeepBookRefreshController extends RefreshController {
  KeepBookRefreshController() : super(initialRefresh: false);
}

/// 下拉更新统一样式。
class MagicRefresher extends StatelessWidget {
  const MagicRefresher({
    super.key,
    required this.controller,
    required this.child,
    this.header = const WaterDropHeader(),
    this.footer,
    this.enablePullDown = true,
    this.enablePullUp = true,
    this.scrollController,
    this.onRefresh,
    this.onLoading,
  });

  final KeepBookRefreshController controller;
  final Widget child;
  final Widget? header;
  final Widget? footer;
  final bool enablePullDown;
  final bool enablePullUp;
  final ScrollController? scrollController;
  final VoidCallback? onRefresh;
  final VoidCallback? onLoading;

  @override
  Widget build(BuildContext context) {
    return SmartRefresher(
      controller: controller,
      scrollController: scrollController,
      header: header,
      footer: footer,
      enablePullDown: enablePullDown,
      enablePullUp: enablePullUp,
      onRefresh: onRefresh,
      onLoading: onLoading,
      child: child,
    );
  }
}